package com.xuln.common.category.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Transient;

import com.xuln.framework.entity.BaseEntity;

/**
 * 分类体系
 */

@Entity
public class Category extends BaseEntity {
	private static final long serialVersionUID = -1429580114942414966L;

	public static final String PATH_SEPARATOR = ",";// 树路径分隔符

	@Column(nullable = false)
	private String name;// 分类名称
	@Column(nullable = false, length = 10)
	private String categoryType;
	@Column(length = 500)
	private String metaKeywords;// 页面关键词
	@Column(length = 5000)
	private String metaDescription;// 页面描述
	@Column(length = 5000)
	private String description;// 页面描述
	@Column
	private Integer orderList;// 排序
	@Column(nullable = true, length = 1000)
	private String path;// 树路径

	@Column(nullable = false)
	private Long parentId = 0L;// 上级分类

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCategoryType() {
		return categoryType;
	}

	public void setCategoryType(String categoryType) {
		this.categoryType = categoryType;
	}

	public String getMetaKeywords() {
		return metaKeywords;
	}

	public void setMetaKeywords(String metaKeywords) {
		this.metaKeywords = metaKeywords;
	}

	public String getMetaDescription() {
		return metaDescription;
	}

	public void setMetaDescription(String metaDescription) {
		this.metaDescription = metaDescription;
	}

	public Integer getOrderList() {
		return orderList;
	}

	public void setOrderList(Integer orderList) {
		this.orderList = orderList;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	// 获取分类层级（顶级分类：0）
	@Transient
	public Integer getLevel() {
		return path.split(PATH_SEPARATOR).length - 1;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}